package com.assembler.app.debruij.succinct;

import java.util.List;

import com.assembler.app.debruij.model.CompositeItem;
import com.assembler.app.debruij.model.Edge;

/**
 * This class provides the method to convert the Succinct De Bruijn Graph to the UnipathGraph.
 * 
 * This class is a part of the lab rotation project for PhD - students January 2014.
 * School of Computing
 * National University Singapore.
 * 
 * @author Iana Pyrogova, Abha Belorkar
 * @version 1.0.1
 */
public class UnipathGraph extends AbstractGraph{
	
	public static void buildUnipath(DeBruijnGraph graph) {
		for (int j = 0; j < graph.getComposites().size(); j++) {
			CompositeItem currentComposite = graph.getComposites().get(j);
			if (graph.indegree(j) == 1
					&& graph.outdegree(currentComposite.getNode(), graph.getNodeList()) == 1) {
				// TODO check node isFirstNode and isLastNode
				List<CompositeItem> parents = graph.getAllParentsForNode(j);
				int perentIndex = graph.getComposites().indexOf(parents.get(0));
				Edge tmp = new Edge(currentComposite.getNode().getNode());
				graph.getComposites().get(perentIndex).setEdge(tmp);//set new outgoing edge for perent node

			}
		}
	}

}
